package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Map的遍历,支持三种遍历方式"
 * 1:遍历所有的key
 * 2:编译所有的键值
 * 3:遍历所有的value(相对不常用)
 * */

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("数学",84);
        map.put("语文",94);
        map.put("英语",90);
        map.put("化学",99);
        map.put("物理",88);
        System.out.println(map);

        Set<String> str = map.keySet();
        System.out.println(str);
        for (String key:str){
            System.out.println("key:"+key);
        }
        System.out.println("=================");
        Set<Map.Entry<String,Integer>> set = map.entrySet();
        for (Map.Entry<String,Integer> str1 :set){
            String s = str1.getKey();
            Integer s1 = str1.getValue();
            System.out.println("key:"+s+",value:"+s1);
        }
        Collection<Integer> value =map.values();
        for (Integer e :value){
            System.out.println("value:"+e);
        }

        value.forEach(System.out::println);

        map.forEach(( s,integer)-> {System.out.println(s+":"+integer);});

    }
}
